<?php

require_once dirname(__FILE__).'/../lib/egresosGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/egresosGeneratorHelper.class.php';

/**
 * egresos actions.
 *
 * @package    gescell
 * @subpackage egresos
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class egresosActions extends autoEgresosActions
{
    public function executeNew(sfWebRequest $request)
  {
    $this->form = $this->configuration->getForm();
    $this->egresos = $this->form->getObject();
    $this->form->form2 = new categoria_egresosForm();
    $this->form->setdefault('sf_guard_user', $this->getUser()->getGuardUser()->getId());
    
  }
   public function executeEdit(sfWebRequest $request)
  {

    $this->egresos = $this->getRoute()->getObject();
    
    
       $this->form = $this->configuration->getForm($this->egresos);
       $this->form->form2 = new categoria_egresosForm();
       //$this->form->setdefault('sf_guard_user', $this->getUser()->getGuardUser()->getId());
    
      }
  public function executeAgregartipo(sfWebRequest $request){
            if ($request->isXmlHttpRequest()){
                $this->Form2 = new categoria_egresosForm();
                $this->procesarForm($request, $this->Form2);
                $form = new egresosForm();
                //return $this->rendertext('Guardado');
                return $this->renderpartial('egresos/categoriaegreso1',array('form'=>$form));
            }
        }
  protected function procesarForm(sfWebRequest $request, sfForm $form)
        {
            $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
            if ($form->isValid()){
                $categoria_egresos = $form->save();
            }

        }
        public function executeDelete(sfWebRequest $request)
  {
    if ($this->getRoute()->getObject()->EsBorrable()){
    $request->checkCSRFProtection();

    $this->dispatcher->notify(new sfEvent($this, 'admin.delete_object', array('object' => $this->getRoute()->getObject())));

    $this->getRoute()->getObject()->delete();

    $this->getUser()->setFlash('notice', 'The item was deleted successfully.');

    $this->redirect('@egresos');
    }
    else{
         $this->redirect('facturas/mensaje?mensaje=Lo sentimos pero la caja esta cerrada y ya no es posible modificar los datos');
    }
  }
  public function executeUpdate(sfWebRequest $request)
  {
    $this->egresos = $this->getRoute()->getObject();

    if($this->egresos->EsBorrable() ){
       $this->form = $this->configuration->getForm($this->egresos);
       $this->processForm($request, $this->form);
       $this->setTemplate('edit');
    }
    else
       $this->redirect('facturas/mensaje?mensaje=Lo sentimos pero la caja esta cerrada y ya no es posible modificar los datos');

  }

}
